TCF_CODE=$(pwd)/../code
export LD_LIBRARY_PATH=$TCF_CODE:$LD_LIBRARY_PATH

dd0=$(pwd)

######################################################################

#full data sets
dsets=$(find $(pwd)/*/LHC*/ -type d | grep -v "/cohe" )
jobid=full

#short test, selecting only one data set
#dsets=$(echo $(pwd)/DATA_all/LHC10hCEN0_DATA_RAA_ETA0/ )
#jobid=short

#with hard coded energy loss between TPC inner wall and vertex, to switch off, just put nothing, i.e. ecor=""
ecor=_HASENERGYLOSSCORRECTION

#to loop over all possible TOF configuration
tofopt=$(echo TOF1SIGMA TOF2SIGMA noTOF)

######################################################################
#FF
#dsets=$(echo $(pwd)/DATA*/histRec*)
#jobid=FF
#ecor=_HASENERGYLOSSCORRECTION_NoHighDensity
#tofopt=$(echo noTOF)

#_WithRef #_NoHighDensity_MeanFixTrue_ResolutionFixTrue
######################################################################

#BetheBloch parametrization
mm=$(echo  mBB aleph) 

#weight, format "anchor5"=1e3, "anchor6"=1e6
anc=$(echo anchor4)

#option, only 0 should be used
regopt=$(echo 0) # 1 2 3 4

#resolution parametrization
sigma=$(echo 2000 3000)

#regularization range 2=direct neighbour
intp=$(echo 2)

for ii in $dsets; do
    for method in $(echo $mm); do 
        for jj in $(echo $anc); do
            for reg in $(echo $regopt); do 
                for tof in $(echo $tofopt); do
                    dir=$ii/coherent/$tof/$method\_$jj\_RegOpt$reg$ecor
                    echo $dir; 
                    mkdir -p $dir; 
                    
                    cd $dir    
                    
                    cp $dd0/{fith,mn2d,dofith.sh,domn2d.sh} .
                    
                    jobfile=$jobid\subfit.sh

                    cat > $jobfile <<EOF
uname -a

#source /hera/alice/xlu/alice/script/hera-evn.sh -n

cd $dir

echo ls
ls
echo

echo pwd
pwd
echo

echo go

./dofith.sh ../../../histRec*.root

for res in \$(echo $sigma); do 
    for dbin in \$(echo $intp); do 
        echo hi
        ./domn2d.sh \$res \$dbin
    done; 
done

EOF

 #                   qsub -cwd -l h_rt=10:0:0,h_rss=2G  ./$jobfile 
chmod +x $jobfile;./$jobfile               

#for short test
exit
                    cd $dd0
                done;
            done;
        done;
    done;
done

